#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'beta_test train_sub'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

:<<predict_score
info=~/sg-users/yangfei/data/meth/beta_tes/450k/info1.txt
predict_score=predict_score.txt

grep GSE $predict_score|cut -f4 |cut -f1 -d.|sort|uniq > project


for i in `cat project`; do
    grep $i $info > $i.pre
    grep $i $predict_score |cut -f1|sort|uniq -c|sed 's/^  *//g'|sort -k1,1nr -t ' ' >> $i.pre
    echo >> $i.pre
done
    
cat *.pre > class.pre.txt

rm *.pre project 
predict_score

:<<depth
#-----------------------
cut -f1,2 --output-delimiter=- $out_prefix.beta.txt > $out_prefix.pos
cut -f4 $out_prefix.beta.txt > $out_prefix.depth
paste $out_prefix.pos $out_prefix.depth > $out_prefix.pos.depth

depth.py -p$out_prefix $out_prefix.pos.depth

rm $out_prefix.pos $out_prefix.depth
#-----------------------------
depth


:> $out_prefix.ids.multi.txt
for i in $@; do 
    cut -f1 $i |sed '1d'> id.tmp
    cat $out_prefix.ids.multi.txt id.tmp > $out_prefix.ids.multi.txt.tmp
    mv $out_prefix.ids.multi.txt.tmp $out_prefix.ids.multi.txt
done

sort $out_prefix.ids.multi.txt |uniq -c|sed 's/^  *//' |sort -k1,1nr -t' ' > $out_prefix.id.repeat.txt

echo "#$@ $#" > $out_prefix.id.repeat.freq.txt
echo feature_num repeat_time >>$out_prefix.id.repeat.freq.txt
cut -f1 $out_prefix.id.repeat.txt -d' '|uniq -c| sed 's/^  *//' |awk '{print $1, $1/2800000, $2}'>> $out_prefix.id.repeat.freq.txt

    
